package com.ptu.controller.user;

import com.ptu.server.ProductServer;
import com.ptu.util.Result;
import com.ptu.vo.HotVO;
import com.ptu.vo.ProductFlVO;
import com.ptu.vo.ProductVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userProductController")
@Slf4j
@Tag(name = "商品模块")
@RequestMapping("/product")
public class ProductController {

    @Autowired
    ProductServer productServer;

    @Operation(summary = "获取商品分类信息")
    @GetMapping("/list")
    public Result<List> getCategory(Integer categoryId) {
        System.out.println("获取商品分类信息" + categoryId);
        List<ProductFlVO> list = productServer.getCategory(categoryId);
        System.out.println("获取商品分类信息成功 ProductFlVO" );
        //log.info("获取商品分类信息成功{}", list );
        return Result.success(list);
    }

    @Operation(summary = "根据id获取商品详情信息")
    @GetMapping("/detail")
    public Result<ProductVO> getDetailById(int id) {
        ProductVO productVO = productServer.getDetailById(id);
        return Result.success(productVO);
    }

    @Operation(summary = "根据name和分类id获取商品信息")
    @GetMapping("/search")
    public Result<List> getProductByName(String name, Integer categoryId) {
        List<ProductVO> list = productServer.getProductByName(name, categoryId);
        return Result.success(list);
    }

    //收藏，取消收藏
    @Operation(summary = "收藏商品")
    @GetMapping("/favorite")
    public Result<Void> favorite(int id) {
        System.out.println("收藏商品/取消收藏" + id);
        productServer.favorite(id);
        return Result.success();
    }

    //按名字搜索商品
    @Operation(summary = "按名字搜索商品")
    @GetMapping("/searchByName")
    public Result<List> searchByName(String name) {
        System.out.println("按名字搜索商品" + name);
        List<ProductVO> list = productServer.getProductByName(name, null);
        return Result.success(list);
    }

    @Operation(summary = "获取热门商品列表")
    @GetMapping("/hotList")
    public List<HotVO> getHotListByCategory(String type, Integer categoryId) {
        System.out.println("获取热门商品列表");
        List<HotVO> list = productServer.getHotListByCategory(type, categoryId);
        return list;
    }

    @Operation(summary = "获取用户销售榜单")
    @GetMapping("/userHotList")
    public List<HotVO> getUserHotList(String type, Integer categoryId) {
        System.out.println("获取用户销售榜单");
        List<HotVO> list = productServer.getUserHotListByCategory(type, categoryId);
        return list;
    }

    //获取收藏列表
//    @Operation(summary = "获取收藏列表")
//    @GetMapping("/favoriteList")
//    public Result<List> favoriteList() {
//        System.out.println("获取收藏列表");
//        List<ProductVO> list = productServer.getFavoriteList();
//        return Result.success(list);
//    }
}
